using System;
using System.Collections.Generic;
using System.Text;
using Entities;
using DAL;
using Utility;

namespace BUS
{
    public class tbSanPhamBUS
    {
        #region"Insert"
        public static int Insert(tbSanPham sanpham)
        {
            tbSanPhamDAL sanphamDAL = new tbSanPhamDAL();
          return  sanphamDAL.Insert(sanpham);
        }
        #endregion
        #region"Update"
        public static void Update(tbSanPham sanpham)
        {
            tbSanPhamDAL sanphamDAL = new tbSanPhamDAL();
            sanphamDAL.Update(sanpham);
        }
        #endregion
        #region"Delete"
        public static void Delete(int iD)
        {
            tbSanPhamDAL sanphamDAL = new tbSanPhamDAL();
            sanphamDAL.Delete(iD);
        }
        #endregion
        #region"Get"
        public static tbSanPhamCollection Get(string where,
           int pageindex,
           int pagesize,
           string orderby,
           string orderdirection,
           out int total)
        {
            tbSanPhamDAL sanPhamDAL = new tbSanPhamDAL();
            return sanPhamDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        #endregion
        #region"Get All"
        public static tbSanPhamCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbSanPhamDAL sanPhamDAL = new tbSanPhamDAL();
            return sanPhamDAL.Get(cri.Criter, 0, 0, tbSanPhamColumns.MaSP.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        #endregion
        #region"Get By ID"
        public static tbSanPham GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbSanPhamColumns.MaSP.ToString(), Condition.EQUAL, iD);
            tbSanPhamDAL sanphamDAL = new tbSanPhamDAL();
            tbSanPhamCollection sanphamCollection = sanphamDAL.Get(cri.Criter,
                0, 0, tbSanPhamColumns.MaSP.ToString(), OrderDirection.ASC.ToString(), out total);
            if (sanphamCollection.Count > 0)
                return sanphamCollection[0];
            return null;
        }
        #endregion
    }
}
